#include "Global.h"
QQData g_User_Self;
int GetHour()
{
    QDateTime time = QDateTime::currentDateTime();//获取系统现在的时间
    QString str = time.toString("hh"); //设置显示格式
    return str.toInt();
}


// 获取HTTP头指定字段名称的值
QString GetRespHeader(std::vector<QString>* arrRespHeader, wchar_t* lpszName, int nIndex)
{
    QString strLine;
    int nNameLen, nIndex2 = 0;
    if (NULL == arrRespHeader || NULL == lpszName)
        return ("");

    nNameLen = wcslen(lpszName);
    if (nNameLen <= 0)
        return ("");

    for (int i = 0; i < (int)arrRespHeader->size(); i++)
    {
        strLine = (*arrRespHeader)[i];
        if (!wcsnicmp(strLine.toStdWString().c_str(), lpszName, nNameLen))
        {
            if (nIndex == nIndex2)
            {
                int nPos = nNameLen;
                int nLineLen = (int)strLine.size();

                for(; nPos < nLineLen && strLine[nPos] == (' '); ++nPos);	// 跳过前导空格
                if (strLine[nPos] == (':'))	// 跳过“:”符号
                    nPos++;
                for(; nPos < nLineLen && strLine[nPos] == (' '); ++nPos);	// 跳过前导空格

                return strLine.mid(nPos);
            }

            nIndex2++;
        }
    }

    return ("");
}


QString GetBetweenString(const wchar_t * pStr, const wchar_t * pStart, const wchar_t * pEnd)
{
    QString strText;

    if (NULL == pStr || NULL == pStart || NULL == pEnd)
        return ("");

    int nStartLen = wcslen(pStart);

    const wchar_t * p1 = wcsstr(pStr, pStart);
    if (NULL == p1)
        return ("");

    const wchar_t * p2 = wcsstr(p1+nStartLen, pEnd);
    if (NULL == p2)
        return ("");

    int nLen = p2-(p1+nStartLen);
    if (nLen <= 0)
        return ("");

    wchar_t * lpText = new wchar_t[nLen+1];
    if (NULL == lpText)
        return ("");

    memset(lpText, 0, (nLen+1)*sizeof(wchar_t));
    wcsncpy(lpText, p1+nStartLen, nLen);
    strText = QString::fromWCharArray(lpText) ;
    delete []lpText;

    return strText;
}
